﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

using NUnit.Framework;
using System.Resources;

namespace HappyTemplate.Tests
{
	[TestFixture]
	public class ErrorMessageTests
	{
		private static void MatchEnumToResources(Type enmType, ResourceManager resourceManager)
		{
			ResourceSet resourceSet = resourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, false);
			HashSet<string> names = new HashSet<string>();

			foreach (string name in Enum.GetNames(enmType))
			{
				names.Add(name);
				if(resourceSet.GetString(name) == null)
					Assert.Fail("Enum value {0}.{1} does not have a corresponding string in the resource set",
						enmType.FullName, name);
			}

			foreach(DictionaryEntry e in resourceSet)
				if(!names.Contains((string)e.Key))
					Assert.Fail("Resource {0} does not have a corresponding value in the enum {1}",
						e.Key, enmType.FullName);
		}

		[Test]
		public void CheckTemplateExceptionMessages()
		{
			MatchEnumToResources(typeof(TemplateErrorCode), Resources.TemplateErrorMessages.ResourceManager);
		}

		[Test]
		public void CheckExecutionExceptionMessages()
		{
			MatchEnumToResources(typeof(TemplateExecutionErrorCode),
			                     Resources.ExecutionErrorMessages.ResourceManager);
		}
	}
}
